unit Class_Memb;

interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TMEMB=class(TUniEngine)
  private
    FUNITLINK : string;
    FMEMBIDEX : Integer;
    FFAMINAME : string;
    FMEMBNAME : string;
    FMEMBSEX  : Integer;
    FMEMBFETE : TDateTime;
    FMEMBCODE : string;
    FMEMBCARD : string;
    FMEMBMOBI : string;
    FMEMBCEGE : string;
    FMEMBADDR : string;
    FMEMBDATE : TDateTime;
    FMEMBCATE : Integer;
    FMEMBMEMO : string;
    FMEMBMONY : Extended;
    FBOOLSMSX : Integer;
    FMEMBSERV : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property UNITLINK : string read FUNITLINK  write FUNITLINK;
    property MEMBIDEX : Integer read FMEMBIDEX  write FMEMBIDEX;
    property FAMINAME : string read FFAMINAME  write FFAMINAME;
    property MEMBNAME : string read FMEMBNAME  write FMEMBNAME;
    property MEMBSEX  : Integer read FMEMBSEX   write FMEMBSEX;
    property MEMBFETE : TDateTime read FMEMBFETE  write FMEMBFETE;
    property MEMBCODE : string read FMEMBCODE  write FMEMBCODE;
    property MEMBCARD : string read FMEMBCARD  write FMEMBCARD;
    property MEMBMOBI : string read FMEMBMOBI  write FMEMBMOBI;
    property MEMBCEGE : string read FMEMBCEGE  write FMEMBCEGE;
    property MEMBADDR : string read FMEMBADDR  write FMEMBADDR;
    property MEMBDATE : TDateTime read FMEMBDATE  write FMEMBDATE;
    property MEMBCATE : Integer read FMEMBCATE  write FMEMBCATE;
    property MEMBMEMO : string read FMEMBMEMO  write FMEMBMEMO;
    property MEMBMONY : Extended read FMEMBMONY  write FMEMBMONY;
    property BOOLSMSX : Integer read FBOOLSMSX  write FBOOLSMSX;
    property MEMBSERV : string read FMEMBSERV  write FMEMBSERV;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AMEMB:TMEMB):TMEMB;overload;
    class procedure CopyIt(AMEMB:TMEMB;var Result:TMEMB);overload;
  end;

implementation

{ TMEMB }
procedure TMEMB.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('MEMB_IDEX').Value := MEMBIDEX;
        ParamByName('FAMI_NAME').Value := FAMINAME;
        ParamByName('MEMB_NAME').Value := MEMBNAME;
        ParamByName('MEMB_SEX').Value := MEMBSEX;
        ParamByName('MEMB_FETE').Value := MEMBFETE;
        ParamByName('MEMB_CODE').Value := MEMBCODE;
        ParamByName('MEMB_CARD').Value := MEMBCARD;
        ParamByName('MEMB_MOBI').Value := MEMBMOBI;
        ParamByName('MEMB_CEGE').Value := MEMBCEGE;
        ParamByName('MEMB_ADDR').Value := MEMBADDR;
        ParamByName('MEMB_DATE').Value := MEMBDATE;
        ParamByName('MEMB_CATE').Value := MEMBCATE;
        ParamByName('MEMB_MEMO').Value := MEMBMEMO;
        ParamByName('MEMB_MONY').Value := MEMBMONY;
        ParamByName('BOOL_SMSX').Value := BOOLSMSX;
        ParamByName('MEMB_SERV').Value := MEMBSERV;
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('MEMB_IDEX').Value := MEMBIDEX;
        ParamByName('FAMI_NAME').Value := FAMINAME;
        ParamByName('MEMB_NAME').Value := MEMBNAME;
        ParamByName('MEMB_SEX').Value := MEMBSEX;
        ParamByName('MEMB_FETE').Value := MEMBFETE;
        ParamByName('MEMB_CODE').Value := MEMBCODE;
        ParamByName('MEMB_CARD').Value := MEMBCARD;
        ParamByName('MEMB_MOBI').Value := MEMBMOBI;
        ParamByName('MEMB_CEGE').Value := MEMBCEGE;
        ParamByName('MEMB_ADDR').Value := MEMBADDR;
        ParamByName('MEMB_DATE').Value := MEMBDATE;
        ParamByName('MEMB_CATE').Value := MEMBCATE;
        ParamByName('MEMB_MEMO').Value := MEMBMEMO;
        ParamByName('MEMB_MONY').Value := MEMBMONY;
        ParamByName('BOOL_SMSX').Value := BOOLSMSX;
        ParamByName('MEMB_SERV').Value := MEMBSERV;
      end;
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('MEMB_IDEX').Value := MEMBIDEX;

      end;
    end;
  end;
end;

function TMEMB.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_MEMB',['UNIT_LINK',UNITLINK,'MEMB_IDEX',MEMBIDEX],AUniConnection);
end;

function TMEMB.GetNextIdex: Integer;
begin

end;

function TMEMB.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin
  Result:=CheckField('MEMB_IDEX','TBL_MEMB',['UNIT_LINK',UNITLINK],AUniConnection);
end;

function TMEMB.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_MEMB WHERE   UNIT_LINK=:UNIT_LINK AND MEMB_IDEX=:MEMB_IDEX';
end;

function TMEMB.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_MEMB'
         +'    ( UNIT_LINK, MEMB_IDEX, FAMI_NAME, MEMB_NAME, MEMB_SEX'
         +'    , MEMB_FETE, MEMB_CODE, MEMB_CARD, MEMB_MOBI, MEMB_CEGE'
         +'    , MEMB_ADDR, MEMB_DATE, MEMB_CATE, MEMB_MEMO, MEMB_MONY'
         +'    , BOOL_SMSX, MEMB_SERV)'
         +'    VALUES'
         +'    (:UNIT_LINK,:MEMB_IDEX,:FAMI_NAME,:MEMB_NAME,:MEMB_SEX'
         +'    ,:MEMB_FETE,:MEMB_CODE,:MEMB_CARD,:MEMB_MOBI,:MEMB_CEGE'
         +'    ,:MEMB_ADDR,:MEMB_DATE,:MEMB_CATE,:MEMB_MEMO,:MEMB_MONY'
         +'    ,:BOOL_SMSX,:MEMB_SERV)';
end;

function TMEMB.GetStrsIndex: string;
begin
  Result:=Format('%S-%D',[UNITLINK,MEMBIDEX]);
end;

function TMEMB.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_MEMB SET'
         +'    FAMI_NAME=:FAMI_NAME,'
         +'    MEMB_NAME=:MEMB_NAME,'
         +'    MEMB_SEX=:MEMB_SEX,'
         +'    MEMB_FETE=:MEMB_FETE,'
         +'    MEMB_CODE=:MEMB_CODE,'
         +'    MEMB_CARD=:MEMB_CARD,'
         +'    MEMB_MOBI=:MEMB_MOBI,'
         +'    MEMB_CEGE=:MEMB_CEGE,'
         +'    MEMB_ADDR=:MEMB_ADDR,'
         +'    MEMB_DATE=:MEMB_DATE,'
         +'    MEMB_CATE=:MEMB_CATE,'
         +'    MEMB_MEMO=:MEMB_MEMO,'
         +'    MEMB_MONY=:MEMB_MONY,'
         +'    BOOL_SMSX=:BOOL_SMSX,'
         +'    MEMB_SERV=:MEMB_SERV'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   MEMB_IDEX=:MEMB_IDEX';
end;

constructor TMEMB.Create;
begin
  FUNITLINK:='0001-0001';
end;

destructor TMEMB.Destroy;
begin

  inherited;
end;

class function TMEMB.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TMEMB.Create;

  with TMEMB(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='UNIT_LINK' then
      begin
        UNITLINK :=Field.AsString;
      end else
      if FieldName='MEMB_IDEX' then
      begin
        MEMBIDEX :=Field.AsInteger;
      end else
      if FieldName='FAMI_NAME' then
      begin
        FAMINAME :=Field.AsString;
      end else
      if FieldName='MEMB_NAME' then
      begin
        MEMBNAME :=Field.AsString;
      end else
      if FieldName='MEMB_SEX' then
      begin
        MEMBSEX  :=Field.AsInteger;
      end else
      if FieldName='MEMB_FETE' then
      begin
        MEMBFETE :=Field.AsDateTime;
      end else
      if FieldName='MEMB_CODE' then
      begin
        MEMBCODE :=Field.AsString;
      end else
      if FieldName='MEMB_CARD' then
      begin
        MEMBCARD :=Field.AsString;
      end else
      if FieldName='MEMB_MOBI' then
      begin
        MEMBMOBI :=Field.AsString;
      end else
      if FieldName='MEMB_CEGE' then
      begin
        MEMBCEGE :=Field.AsString;
      end else
      if FieldName='MEMB_ADDR' then
      begin
        MEMBADDR :=Field.AsString;
      end else
      if FieldName='MEMB_DATE' then
      begin
        MEMBDATE :=Field.AsDateTime;
      end else
      if FieldName='MEMB_CATE' then
      begin
        MEMBCATE :=Field.AsInteger;
      end else
      if FieldName='MEMB_MEMO' then
      begin
        MEMBMEMO :=Field.AsString;
      end else
      if FieldName='MEMB_MONY' then
      begin
        MEMBMONY :=Field.AsFloat;
      end else
      if FieldName='BOOL_SMSX' then
      begin
        BOOLSMSX :=Field.AsInteger;
      end else
      if FieldName='MEMB_SERV' then
      begin
        MEMBSERV :=Field.AsString;
      end;
    end
  end;
end;

class procedure TMEMB.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TMEMB(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='UNIT_LINK' then
      begin
        UNITLINK :=Field.AsString;
      end else
      if FieldName='MEMB_IDEX' then
      begin
        MEMBIDEX :=Field.AsInteger;
      end else
      if FieldName='FAMI_NAME' then
      begin
        FAMINAME :=Field.AsString;
      end else
      if FieldName='MEMB_NAME' then
      begin
        MEMBNAME :=Field.AsString;
      end else
      if FieldName='MEMB_SEX' then
      begin
        MEMBSEX  :=Field.AsInteger;
      end else
      if FieldName='MEMB_FETE' then
      begin
        MEMBFETE :=Field.AsDateTime;
      end else
      if FieldName='MEMB_CODE' then
      begin
        MEMBCODE :=Field.AsString;
      end else
      if FieldName='MEMB_CARD' then
      begin
        MEMBCARD :=Field.AsString;
      end else
      if FieldName='MEMB_MOBI' then
      begin
        MEMBMOBI :=Field.AsString;
      end else
      if FieldName='MEMB_CEGE' then
      begin
        MEMBCEGE :=Field.AsString;
      end else
      if FieldName='MEMB_ADDR' then
      begin
        MEMBADDR :=Field.AsString;
      end else
      if FieldName='MEMB_DATE' then
      begin
        MEMBDATE :=Field.AsDateTime;
      end else
      if FieldName='MEMB_CATE' then
      begin
        MEMBCATE :=Field.AsInteger;
      end else
      if FieldName='MEMB_MEMO' then
      begin
        MEMBMEMO :=Field.AsString;
      end else
      if FieldName='MEMB_MONY' then
      begin
        MEMBMONY :=Field.AsFloat;
      end else
      if FieldName='BOOL_SMSX' then
      begin
        BOOLSMSX :=Field.AsInteger;
      end else
      if FieldName='MEMB_SERV' then
      begin
        MEMBSERV :=Field.AsString;
      end;
    end
  end;
end;

class function  TMEMB.CopyIt(AMEMB: TMEMB): TMEMB;
begin
  Result:=TMEMB.Create;
  TMEMB.CopyIt(AMEMB,Result)
end;

class procedure TMEMB.CopyIt(AMEMB:TMEMB;var Result:TMEMB);
begin
  if Result=nil then Exit;
  Result.UNITLINK :=AMEMB.UNITLINK;
  Result.MEMBIDEX :=AMEMB.MEMBIDEX;
  Result.FAMINAME :=AMEMB.FAMINAME;
  Result.MEMBNAME :=AMEMB.MEMBNAME;
  Result.MEMBSEX  :=AMEMB.MEMBSEX;
  Result.MEMBFETE :=AMEMB.MEMBFETE;
  Result.MEMBCODE :=AMEMB.MEMBCODE;
  Result.MEMBCARD :=AMEMB.MEMBCARD;
  Result.MEMBMOBI :=AMEMB.MEMBMOBI;
  Result.MEMBCEGE :=AMEMB.MEMBCEGE;
  Result.MEMBADDR :=AMEMB.MEMBADDR;
  Result.MEMBDATE :=AMEMB.MEMBDATE;
  Result.MEMBCATE :=AMEMB.MEMBCATE;
  Result.MEMBMEMO :=AMEMB.MEMBMEMO;
  Result.MEMBMONY :=AMEMB.MEMBMONY;
  Result.BOOLSMSX :=AMEMB.BOOLSMSX;
  Result.MEMBSERV :=AMEMB.MEMBSERV;
end;

end.

